import { Leafer, Pen, DragEvent, PointerEvent } from 'leafer-ui';
import { Editor } from '@leafer-in/editor/src';


export const rectDragEventStart = (
  e: DragEvent,
  leafer: Leafer,
): [number, number, Pen] => {
  const pen = new Pen({ name: 'rectPen' });

  pen.setStyle({
    fill: '#44D7B6',
    name: 'rectPen',
  });
  leafer.add(pen);
  
  const inner = e.getInner(pen);
  pen.moveTo(inner.x, inner.y);
  return [inner.x, inner.y, pen];
};

export const rectDragEventDrag = (
  e: DragEvent,
  pointX: number,
  pointY: number,
  pen: Pen,
  editor: Editor
) => {
  const inner = e.getInner(pen);
  pen.beginPath();
  pen.rect(pointX, pointY, inner.x - pointX, inner.y - pointY);
  pen.paint();
  editor.target = pen;
};
